package com.youku.plugins.commonui.view.noticeCard
{
   import flash.net.URLLoader;
   import flash.display.Loader;
   import flash.events.Event;
   import flash.events.IOErrorEvent;
   import flash.events.SecurityErrorEvent;
   import com.adobe.json.JSON;
   import flash.net.URLRequest;
   import com.youku.plugins.commonui.CommonUIEvent;
   
   public class PayCardLoader extends BaseNoticeCard
   {
      
      public function PayCardLoader() {
         super();
         this.init();
      }
      
      private var _urlLoader:URLLoader;
      
      private var _loader:Loader;
      
      private var _swf;
      
      override protected function init() : void {
         this._urlLoader = new URLLoader();
         this._urlLoader.addEventListener(Event.COMPLETE,this.onJsonLoaded);
         this._urlLoader.addEventListener(IOErrorEvent.IO_ERROR,this.onError);
         this._urlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR,this.onError);
         this._loader = new Loader();
         this._loader.contentLoaderInfo.addEventListener(Event.COMPLETE,this.onLoaded);
         this._loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,this.onError);
         this._loader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR,this.onError);
         addChild(this._loader);
      }
      
      private function onJsonLoaded(param1:Event) : void {
         var obj:Object = null;
         var e:Event = param1;
         var str:String = this._urlLoader.data as String;
         if(str == null || str == "")
         {
            this.onError(null);
            return;
         }
         try
         {
            obj = com.adobe.json.JSON.decode(str);
         }
         catch(e:Error)
         {
            onError(null);
            return;
         }
         if(obj.data == null)
         {
            this.onError(null);
            return;
         }
         if(obj.data.url == null || obj.data.url == "")
         {
            this.onError(null);
            return;
         }
         this._loader.load(new URLRequest(obj.data.url));
      }
      
      override public function load(param1:String) : void {
         this._urlLoader.load(new URLRequest(param1));
      }
      
      private function onError(param1:Event) : void {
         dispatchEvent(new CommonUIEvent(CommonUIEvent.NOTICE_PAY_BUY));
      }
      
      private function onLoaded(param1:Event) : void {
         this._swf = param1.target.content;
         this.updateLayout();
      }
      
      override public function setSize(param1:Number, param2:Number) : void {
         _width = param1;
         _height = param2;
         this.updateLayout();
      }
      
      override protected function updateLayout() : void {
         if(!this._swf)
         {
            return;
         }
         this._swf.setLocal(_width,_height);
      }
      
      override public function get height() : Number {
         return this.height;
      }
      
      override public function get width() : Number {
         return this.width;
      }
      
      override public function setErrorCode(param1:String) : void {
      }
      
      override public function setStyle(param1:String) : void {
      }
      
      override public function setText(param1:String) : void {
      }
   }
}
